<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html class="win-frame">
<head>
<title>${name_china}管理-编辑${name_china}</title>
<%@include file="/common/head.jsp" %>
<style>
.samecomplex{
	float:left;
	
	
}
.samecomplex>input{
    background:red;
	margin-left:3px;
}
.addtime{
	float: left;
    width: 99px;
    height: 29px;
    background: #0474c8;
    color: #fff;
    text-align: center;
    line-height: 29px;
    margin-left: 11px;
    cursor:pointer;
}
.inputime{
    float: left;
    border: solid 1px #ccc;
    height: 30px;
}
.addgroduct{
	width:120px;
	height:36px;
	background:#f86b67;
	color:#fff;
	line-height:36px;
	cursor:pointer;
	text-align:center;
}
/****蒙版*****/
.maskcon{
	width: 100%;
    height: 100%;
    position: fixed;
    background: rgba(0,0,0,0.6);
    overflow-y: hidden;
    top: 0px;
    z-index:1;
    display:none;
}
.maskMain{
    width:95%;
    height: 100%;
    background: #fff;
    margin: 0 auto;
    margin-top: 50px;
}
.sameprosty{
	
}
/**规格**/
.addspecbut{
	width:73px;
	height:26px;
	line-height:26px;
	text-align:center;
	color:#fff;
	background:#45b854;
	cursor:pointer;
	float: left;
}
/*****规格蒙版******/
.specmask{
	width: 50%;
    height: 50%;
    background: rgba(0,0,0,0.7);
    z-index: 9;
    position: fixed;
    margin: 0 auto;
    margin-left: 20%;
    margin-top: 6%;
}
.closebut{
    width: 20px;
    height: 20px;
    background: red;
    float: right;
    margin: 6px;
    text-align: center;
    border-radius: 50%;
    font-size: 13px;
    color: #fff;
    line-height: 20px;
    cursor: pointer;
	
}
/****模块****/
.specelement{
    margin: 0 auto;
    text-align: center;
    color: #fff;
    margin-top: 109px;
}
.specinput{
    height: 30px;
    margin-left: 12px;
    color: #555;
    padding-left: 10px;
}
.specsure{
    width: 82px;
    height: 30px;
    background: #ff2040;
    text-align: center;
    line-height: 32px;
    margin: 0 auto;
    margin-top: 40px;
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
}
/***刷新***/
.refresh{
	float: left;
    width: 50px;
    height: 26px;
    background: #e82c0c;
    line-height: 26px;
    text-align: center;
    color: #fff;
    margin-left: 10px;
    cursor: pointer;
}
.procheckbox{
	float:left;
	margin-right: 10px;
}
.sameprobox{
    float: left;
    margin-left: 10px;
    line-height: 28px;
}

.splineclose{
	float: right;
    width: 20px;
    height: 20px;
    background: #000;
    color: #fff;
    font-style: normal;
    text-align: center;
    line-height: 20px;
    border-radius: 50%;
    cursor:pointer;
}
.specline{
	width:60%;

}
.specMain{
	overflow:auto;
		
}
.splinename{
	border-bottom:solid 1px #ccc;
}
.splinecon{
    overflow: auto;
    zoom: 1;
}
.samespline{
	float: left;
    margin-left: 10px;
}
.forclose{
    width: 15px;
    height: 15px;
    line-height: 15px;
    background: red;
    border-radius: 50%;
    text-align: center;
    color: #fff;
    float: right;
    margin-right: 11px;
    cursor: pointer;
}
/****规格展示*****/
.batch-update{
	line-height:30px;
	
}
.batch-update input[type=text]{
	height: 28px;
    width: 100px;
    margin-left: 8px;
    background-color: #fff;
    border-color: #d7d7d7;
    border: solid 1px #ccc;
    text-align:center;
}
.batch-submit{
    width: 80px;
    height: 30px;
    margin-left: 8px;
    border: 1px solid #d7d7d7;
    line-height: 30px;
    text-align: center;
    cursor: pointer;
    background-color: #f8f8f8;
}
.list th{
    border: 1px solid #d2d2d2;
    line-height: 26px;
    padding: 0 2px;
    text-align: center;
    min-width: 90px;
}
.list tr:first-child {
    background-color: #f8f8f8;
}
.list td{
    border: 1px solid #d2d2d2;
    line-height: 26px;
    padding: 0 2px;
    text-align: center;
}
.list td input[type=text], .sku .list th input[type=text] {
    width: 100%;
    height: 20px;
    line-height: 20px;
    text-align: center;
    border-width: 0;
    background-color: #fff;
}
table, td {
    border-collapse: collapse;
    border-spacing: 0;
}
</style>
</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
            <span class="split"></span>
            <span>编辑${name_china}</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
    </div>
    <div class="page-title-border"></div>
</div>

<form id="form" method="post">
    <div class="form-wrapper">
	  <div class="h4 distance-double">
        <span class="h4-title"><i class="icon icon-setting"></i>商品spu</span>
        <span class="h4-border"></span>
      </div>
      
     	 <!-- 隐藏传值商品分类id -->
     	<input type="hidden" id="id" name="id"/> 
	    <input type="hidden" id="codeid" name="codeid" value="${codeid}"/>
	    <%-- <input type="hidden" id="categoryCodeid" name="categoryCodeid" value="${codeid}"/> --%>
	    <input type="hidden" id="properNameAndVal" name="properNameAndVal" value=""/>
	    <input type="hidden" id="goodssku" name="goodssku" value=""/>
	    <input type="hidden" id="resultMap" name="resultMap" value=""/>
	    
	    <input type="hidden" id=couponId name="couponId" />
	    <input type="hidden" id=skuPropertyIds name="skuPropertyIds" />
	    <input type="hidden" id=skuIds name="skuIds" />
	    
	    <input type="hidden" id="startTime"  value="${startTime}"/>
	    <input type="hidden" id="endTime"  value="${endTime}"/>
      
       	<div class="form-cont" id="afterSku">
	        <p class="form-cont-title"><span class="field-required">*</span>商品编码</p>
	        <input type="text" id="spuNum" name="spuNum" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[100]']" readonly/> 
	        <!-- <div >
				<p style="color:red">如不填写，可点击<a onclick="autoCreate()" style="cursor: pointer;">自动生成</a></p>
			</div> -->
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>商品名称</p>
	        <input type="text" id="goodsName" name="goodsName" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[300]']"/> 
	     </div>
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>商品货号</p>
	        <input type="text" id="goodsAtrno" name="goodsAtrno" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[500]']"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>商品公司来源</p>
	        <input type="text" id="companyId" name="companyId" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[500]']"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>商品来源</p>
	        <input type="text" id="goodsSource" name="goodsSource" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[500]']"/> 
	     </div>
	     
	      <div class="form-cont">
	        <p class="form-cont-title">上市时间</p>
	        <input type="text" id="marketDate" name="marketDate" class="summer-input summer-validatebox"  onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" data-validatebox="validType:['maxLength[50]']"/> 
	     </div>
	      <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>分类</p>
	         <input type="text" id="category" name="categoryCodeid" class="summer-input"/>
	        <%-- <input type="text" id="category" name="category" value="${categoryName}" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[300]']" readonly/>  --%>
	     </div>
	     
	      <div class="form-cont">
	        <p class="form-cont-title"><!-- <span class="field-required">*</span> -->商品品牌</p>
	        <input type="text" id="brandId" name="brandId" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[300]']"/> 
	     </div>
	      <div class="form-cont">
	        <p class="form-cont-title">商品发货时间规格</p>
	        <input type="text"  id="goodsDeliveryTimeSpec" name="goodsDeliveryTimeSpec" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[50]']"/>
	     	<!-- <div class="addtime">添加时间</div> -->
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">是否上架</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isShow" class="isShow" >是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isShow" class="isShow" checked>否</div>
	        </div>
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">是否推荐</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isRecommend" class="isRecommend" checked>是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isRecommend" class="isRecommend">否</div>
	        </div>
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">积分抵扣</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isJifenExchange" class="isJifenExchange" checked>是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isJifenExchange" class="isJifenExchange">否</div>
	        </div>
	     </div>
	     <div class="form-cont">
	        <p class="form-cont-title">是否使用系统红包</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isSysCoupon" class="isSysCoupon" checked>是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isSysCoupon" class="isSysCoupon">否</div>
	        </div>
	     </div>
	     <div class="form-cont">
	        <p class="form-cont-title">是否使用商品红包</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isGoodsCoupon" class="isGoodsCoupon" checked>是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isGoodsCoupon" class="isGoodsCoupon">否</div>
	        </div>
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">是否精选</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isJingping" class="isJingping" checked>是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isJingping" class="isJingping" checked>否</div>
	        </div>
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">是否爆款</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isHot" class="isHot" >是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isHot" class="isHot" checked>否</div>
	        </div>
	     </div>
	     <div class="form-cont">
	        <p class="form-cont-title">是否特卖</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isSpecial" class="isSpecial" checked>是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isSpecial" class="isSpecial" checked>否</div>
	        </div>
	     </div>
	     
	      <div class="form-cont">
	        <p class="form-cont-title">是否正品保证</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isQualityAssurance" class="isQualityAssurance" checked>是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isQualityAssurance" class="isQualityAssurance">否</div>
	        </div>
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">是否包邮</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isFreePost" class="isFreePost" checked>是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isFreePost" class="isFreePost">否</div>
	        </div>
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">是否准时到达</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isOnTime" class="isOnTime" checked>是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isOnTime" class="isOnTime">否</div>
	        </div>
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">是否七天无理由退货</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isServenBack" class="isServenBack" checked>是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isServenBack" class="isServenBack">否</div>
	        </div>
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">是否成为进货商品</p>
	        <div class="complex">
	        	<div class="samecomplex"><input type="radio" value="1"  name="isPartner" class="isPartner" checked>是</div>
	        	<div class="samecomplex" style="margin-left:10px"><input type="radio" value="0"  name="isPartner" class="isPartner">否</div>
	        </div>
	     </div>
	     
	     
	     <div class="form-cont">
	     	<p class="form-cont-title">商品主图</p>
	        	<input type="hidden" id="mainImageUrl" name="mainImageUrl"/>
	        <p style="color:red">建议高：188px；宽：375px</p> 
	     </div>
	     <div class="form-cont">
	     	<p class="form-cont-title">商品视频</p>
	        	<input type="hidden" id="detailVideo" name="detailVideo"/>
	        <p style="color:red">建议高：188px；宽：375px</p> 
	     </div>
	     <div class="form-cont">
	     	<p class="form-cont-title">商品轮播图</p>
	        	<input type="hidden" id="banners" name="banners"/>
	        <p style="color:red">建议高：188px；宽：375px</p> 
	     </div>
	     
		<div id="detail">
			<p class="first-caption"></p>
			<div class="first"></div>
			<p class="second-caption"></p>
			<div class="second"></div>
		</div>
	     
	     <div id="text"></div>
		<div class="batch-update">
       	   <label>批量填充</label>
       	   <input type="text" placeholder="价格" class="bacthprice">
       	   <input type="text" placeholder="佣金比例"  class="bacthrate">
       	   <input type="text" placeholder="佣金"  class="bacthbrokage">
       	   <input type="text" placeholder="库存" class="bacthstock">
       	   <input type="button" value="确定" class="batch-submit">
         </div>
		<table border="" cellspacing="" cellpadding="" class="list" id="table1">
			<thead>
				<tr>
					<th class="tab-first-caption"></th>
					<th class="tab-second-caption"></th>
					<th>价钱</th>
					<th>佣金比例</th>
					<th>佣金</th>
					<th>库存</th>
					<th>图片</th>
				</tr>
			</thead>
			<tbody id="tbody"></tbody>
		</table>
		
		<div id="goodsSkuAppend" class="form-cont">
       		 <p class="form-cont-title"><span class="field-required">*</span>商品图片</p>
       		 <select id="goodsSkuimage" class="summer-input summer-validatebox summer-validatebox-text">
       		 </select> 
       		 <a id="uploadGoodsImages" class="btn btn-primary wave distance-right">确定上传</a>
   	    </div>
		
	     <div class="form-cont" id="skuImages">
	        <input type="hidden" id="skuImagesUrls" name="skuImagesUrls"/> 
	     	<!-- 文件上传 -->
	     	<div >
				<div id="skuImagesfileList" class="uploader-list"></div>
				<div id="skuImagesPicker">选择图片</div>
				<p style="color:red">建议高：188px；宽：375px</p>
				
			</div>
    	</div>
    	
    	<div class="form-cont">
	        <p class="form-cont-title">佣金</p>
	        <input type="text" id="wlCommission" name="wlCommission" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[500]']"/> 
	     </div>
	     <div class="form-cont">
	        <p class="form-cont-title">佣金比例</p>
	        <input type="text" id="wlCommissionShare" name="wlCommissionShare" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[500]']"/> 
	     </div>
	     
    	<div class="form-cont">
	        <p class="form-cont-title">进价</p>
	        <input type="text" id="orginPrice" name="orginPrice" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[500]']"/> 
	     </div>
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>价格</p>
	        <input type="text" id="wlPrice" name="wlPrice" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[500]']"/> 
	     </div>
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>城市合伙人进货价格</p>
	        <input type="text" id="cityPrice" name="cityPrice" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[500]']"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>店铺合伙人进货价格</p>
	        <input type="text" id="storePrice" name="storePrice" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[500]']"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>总库存</p>
	        <input type="text" id="totalInventorys" name="totalInventorys" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[500]']"/>
	        <a id="totalCount" class="btn btn-primary wave distance-right">自动获取</a> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">红包价格</p>
	        <input type="text" id="couponMoney" name="couponMoney" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[500]']"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">红包开始时间</p>
	        <input type="text" id="couponStartTime" name="couponStartTime" class="summer-input summer-validatebox"  onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" data-validatebox="validType:['maxLength[50]']"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">红包结束时间</p>
	        <input type="text" id="couponEndTime" name="couponEndTime" class="summer-input summer-validatebox"  onFocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" data-validatebox="validType:['maxLength[50]']"/> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title">劵后价</p>
	        <input type="text" id="conPrice" name="conPrice" class="summer-input summer-validatebox"  data-validatebox="validType:['maxLength[500]']"/> 
	     </div>
		
	     <div class="form-cont">
	       	<p class="form-cont-title">推荐理由</p>
	       	<textarea class="summer-textarea" id="goodsIntroduce" name="goodsIntroduce"></textarea>
		 </div>
			   
		 <div class="form-cont">
		     <p class="form-cont-title">产品参数</p>
		     <textarea class="summer-textarea" id="note" name="note"></textarea>
		  </div>
	    	
	    <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>商品详情图</p>
	        <input type="hidden" id="detailImageUrls" name="detailImageUrls"/>
	     	<div>
				<div id="detailImageUrlsFileList" class="uploader-list"></div>
				<p style="color:red">建议高：无限制；宽：375px</p>
			</div>
	     </div>
	     
	     
     
     <div class="form-btn-wrapper" id="funcbar">
        <a class="btn btn-normal" id="backBtn">关闭</a>
    </div>
  </div>
</form>
<script>
    
  var editData,permission = CommonUtil.getPermission('${name_english}');
    
    $(function () {
    	editData = ${editData}; //反写
    	
    	/* 初始化规格 */
    	$.ajax({
   			url: CONST_URL.INIT_PROPERTY,
   			type: 'POST',
   			dataType: 'json',
   			data:{
   				"codeid": $("#codeid").val()
   			},
   			success:function(data){
   					tab(data); //构建规格表格
   					
         },  
        	error: function (XMLHttpRequest, textStatus, errorThrown) {
               // 状态码
               console.log(XMLHttpRequest.status);
               // 状态
               console.log(XMLHttpRequest.readyState);
               // 错误信息   
               console.log(textStatus);
           }
   		});
    	
    	//填充上传图片list
   	 	$('#form').form().form('loadDataEdit', {
            data: editData
        }); 
    	
   		//红包开始结束时间
     	$("#couponStartTime").val($("#startTime").val());
     	$("#couponEndTime").val($("#endTime").val());
    	
    	//初始化上传插件
    	filePlugin("#skuImagesUrls","#skuImagesPicker","#skuImagesfileList");
    	$("#mainImageUrl").filePlugin({type:'image'});
     	$("#detailVideo").filePlugin({type:'image'});
     	$("#banners").filePlugin({type:'image'});
     	$("#detailImageUrls").filePlugin({type:'image'});
     	
 	   //分类下拉
 	   $('#category').combobox({
     		 async:false,
     		defaultValue:$("#codeid").val(),
             valueField : 'codeid',
             textField : 'name',
             url : CONST_URL.GET_CATEGORY
         });

    	//初始化下拉选项 商品来源
	   	 $('#goodsSource').combobox({
	           valueField : 'code',
	           defaultValue:"yh",
	           async:false,
	           pleaseSelectFlag:false,
	           textField : 'name',
	           url : COMMON_URL.getCode + '?type=T_DM_GOODS_SOURCE'
	       });
	
	   	//初始化下拉选项  商品所属公司
	   	 $('#companyId').combobox({
	            url : CONST_URL.GET_GOODS_COMPANY, 
	            valueField : 'id',
	            async:false,
	            textField : 'companyName'
	        });
	   	 
	   	//初始化下拉选项 商品所属品牌
	   	 $('#brandId').combobox({
	            url : CONST_URL.GET_GOODS_BRAND ,
	            valueField : 'id',
	            async:false,
	            textField : 'brandName'
	     });
	   	
	   //自动获取库存
    	$("#totalCount").click(function(){
    		var aa = 0;
    		$("#tbody").find("tr").each(function(){
    			var bb = $(this).find(".stock").val();
    			aa = parseInt(aa)+parseInt(bb); ;
    		})
    		$("#totalInventorys").val(aa);
    	});
	   	
   		//确定上传按钮
    	$("#uploadGoodsImages").click(function(){
    		var goodsSkuimageValue = $("#goodsSkuimage").val(); //选择框的值
    		var str = "";
    		//获取上传空间里面的值
   			for (var i=0;i<$("#skuImagesfileList").length;i++) {
   				str += $("#skuImagesfileList")[i].innerHTML ;
  	   		}
    		//拼接到表格
   			$("#tbody").find("tr").each(function(){
   				$(this).find("."+goodsSkuimageValue+"").val("");
   				$(this).find("#"+goodsSkuimageValue+"11").find("img").remove();
   				
				$(this).find("#"+goodsSkuimageValue+"11").html(str);
				$(this).find("."+goodsSkuimageValue+"").val($("#skuImagesUrls").val());
			})
			//删除上传控件里面的东西
    		$("#skuImagesfileList").find(".del").trigger("click");
    	})
	   	
	   	//初始化单选框
	   	$(":radio[name='isShow'][value='" + ${isShow} + "']").prop("checked", "checked");
	   	$(":radio[name='isRecommend'][value='" + ${isRecommend} + "']").prop("checked", "checked");
    	$(":radio[name='isJifenExchange'][value='" + ${isJifenExchange} + "']").prop("checked", "checked");
    	$(":radio[name='isSysCoupon'][value='" + ${isSysCoupon} + "']").prop("checked", "checked");
    	$(":radio[name='isGoodsCoupon'][value='" + ${isGoodsCoupon} + "']").prop("checked", "checked");
    	$(":radio[name='isJingping'][value='" + ${isJingping} + "']").prop("checked", "checked");
    	$(":radio[name='isHot'][value='" + ${isHot} + "']").prop("checked", "checked");
    	$(":radio[name='isSpecial'][value='" + ${isSpecial} + "']").prop("checked", "checked");
    	$(":radio[name='isQualityAssurance'][value='" + ${isQualityAssurance} + "']").prop("checked", "checked");
    	$(":radio[name='isFreePost'][value='" + ${isFreePost} + "']").prop("checked", "checked");
    	$(":radio[name='isOnTime'][value='" + ${isOnTime} + "']").prop("checked", "checked");
    	$(":radio[name='isServenBack'][value='" + ${isServenBack} + "']").prop("checked", "checked");
    	$(":radio[name='isPartner'][value='" + ${isPartner} + "']").prop("checked", "checked");
    	
    	//初始化表单内容
     	 $('#form').form({
        	onLoadSuccess:function(data){}
        }).form('loadDataEdit', {
            data: editData
        });
     	 
     	//初始化funcbar
      	$('#funcbar').prepend($.funcbar({
             type: 'button',
             data: permission,
             permit: ['${name_english}:edit']
         }));
     	
      //保存按钮
    	$('#funcbar').on('click', 'a[data-permit="${name_english}:edit"]', submit);
      
    });
    
    
    //表单提交
    function submit(event) {
  		
    	var goodssku=[]
		$("#tbody").find("tr").each(function(){
			goodssku.push($(this).find('.firstValue').text()+","+$(this).find('.secondValue').text()+","+$(this).find('.price').val()+","+$(this).find('.comisrate').val()+","+$(this).find('.brokage').val()+","+$(this).find('.stock').val()+","+$(this).find('.'+$(this).find('.firstValue').text()+'').val())
			console.log(goodssku)
		})
		$("#goodssku").val(goodssku);
  		
    	var goodsSku = $("#goodssku").val();
    	
    	if(null == goodsSku){
    		alert("请选择属性");
    		return
    	}
  		
         $("#form").form({
           buttons : ['#saveBtn'],
           ajax: {
               url: CONST_URL.EDIT,
               data:{
            	"id" : $("#id").val(),
   				"couponMoney": $("#couponMoney").val(),
   				"couponStartTime":$("#couponStartTime").val(),
   				"couponEndTime":$("#couponEndTime").val(),
   				"properNameAndVal" : $("#properNameAndVal").val(),
   				"goodssku" : goodsSku,
   				"couponId" : $("#couponId").val(),
   				"skuIds" : $("#skuIds").val(),
   				"skuPropertyIds" : $("#skuPropertyIds").val()
   			 }
           },
           onSubmitSuccess: function (data) {
        	   
        	 var result = data.result 
        	   
          	 $.stip({
	                type:'ok',//显示类型 有info、 ok、 danger
	                text: '保存成功！',
	                onBeforeHide: function () {
                 	  if (result) {
                          backMain();
                 	  }
	               }
            	});
            }
       }).form("submit"); 
    }
    
  //返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_LIST+"?codeid="+$("#codeid").val();
    }
    
	function tab(str1){
		
		var res = str1;
    	var caption=[];
		var first=["m"];
		var second=[];
		
		var str="";
		
		//商品规格第一层
		if(res.caption[0] != undefined ){
			//表格和参数显示名称		
			$(".first-caption").text(res.caption[0].name);
			$(".tab-first-caption").text(res.caption[0].name);
			
			str="";
			for (var i=0;i<res.first.length;i++) {
				 str+='<input type="checkbox" id='+res.first[i].id+' value='+res.first[i].value+'><label >'+res.first[i].value+'</label>' 
			}
			$(".first").html(str)
			
			//如果只有一个规格，隐藏secound
			if (res.caption[1] == undefined ){	
				$(".second-caption").hide();
				$(".tab-second-caption").hide();
			}
		}
		
		//商品规格第二层
		if (res.caption[1] != undefined ){	
			$(".second-caption").text(res.caption[1].name);
			$(".tab-second-caption").text(res.caption[1].name);
			
			str="";
			for (var i=0;i<res.second.length;i++) {
				str+='<input type="checkbox" id='+res.second[i].id+' value='+res.second[i].value+'><label >'+res.second[i].value+'</label>'
			}
			$(".second").html(str)
		} 
		
		//没有产品规格
		if(res.caption[1] == undefined && res.caption[0] == undefined){
			$("#detail").hide();
			$("#table1").hide();
			$(".batch-update").hide();
		}
		
		
		var skuPropertys = ${skuPropertys}  	//商品属性信息
		var goodsSkus = ${goodsSkus}			//商品skuVo
    	var goodsSkuVos = ${goodsSkuVos}		//商品skuVo
    	var SkuCoupon = ${SkuCoupon}			//商品sku
    	
    	$("#couponId").val(SkuCoupon.id)
    	
    	var skuIds = "";//全部skuId
    	for(var i=0; i < goodsSkus.length;i++){
    		var goodsSkusObj = goodsSkus[i];
    		skuIds+=""+goodsSkusObj.id+"";
    		skuIds+=",";
    	}
    	skuIds = skuIds.substring(0,skuIds.length-1);
    	$("#skuIds").val(skuIds);
    	
    	//遍历商品属性信息，默认选中
    	var skuPropertyIds = ""; //全部propertyId
    	 for(var i=0; i < skuPropertys.length;i++){
   	        var skuPropertysObj = skuPropertys[i];
   	        $("#"+skuPropertysObj.valueId+"").prop("checked", "checked");
   	     	skuPropertyIds+=""+skuPropertysObj.id+"";
   	  		skuPropertyIds+=",";
    	 }
    	 skuPropertyIds = skuPropertyIds.substring(0,skuPropertyIds.length-1);
    	 $("#skuPropertyIds").val(skuPropertyIds);
    	 
    	checkbox();	 //初始化选择器
		if (res.caption[1] == undefined && res.caption[0] != undefined){	
			loadTableFirst();//初始化一层属性
		}
		if (res.caption[1] != undefined && res.caption[0] != undefined ){	
			loadTable(); //初始化表格
		}
		
		//没有产品规格
		if(res.caption[0] == undefined && res.caption[1] == undefined){
			$("#detail").hide();			//属性chenck 隐藏
			$("#table1").hide();			//属性table 隐藏
			$(".batch-update").hide();		//规格展示 隐藏
			$("#goodsSkuAppend").hide();	//商品图片
			$("#skuImages").hide();			//商品图片上传
			$("#totalCount").hide();		//库存自动获取
			
			$("#wlCommissionShare").show();	//佣金比例
			$("#wlCommission").show();		//佣金
			
		}else{
			$("#wlCommissionShare").hide();
			$("#wlCommission").hide();
		}
		
		//重新加载表格
		function loadTableFirst(){
			var first_length=first.length;  	//一级属性长度
			
			var table_str="";
			for(var i=0 ; i < first_length ; i++){
				for(var q=0 ; q < goodsSkuVos.length ; q++){
		   	        var goodsSkuVosObj = goodsSkuVos[q];
		   	        
		   	        if(goodsSkuVosObj.nameId==firstValue[i]){
		   	        	table_str+='<tr id='+firstValue[i]+'>'
						 +'<td >'+first[i]+'</td>' 
						+'<td class="firstValue" style="display:none">'+firstValue[i]+'</td>'
						+'<td class="secondValue" style="display:none"></td>'
						+'<td class="firstName" style="display:none">'+first[i]+'</td>'
						+'<td><input type="text" class="price" value="'+goodsSkuVosObj.skuPrice+'"></td>'
						+'<td><input type="text" class="comisrate" value="'+goodsSkuVosObj.skuProfitPercent+'"></td>'
						+'<td><input type="text" class="brokage" value="'+goodsSkuVosObj.skuProfit+'"></td>'
						+'<td><input type="text" class="stock" value="'+goodsSkuVosObj.totalInventory+'"></td>'
						+'<td><div id="'+firstValue[i]+'11" >'
						+'	<img src="'+goodsSkuVosObj.skuDetails+'" style="width:150px">'
						+'</div><input type="hidden" class="'+firstValue[i]+'" name="skuImagesPicker" value="'+goodsSkuVosObj.skuDetails+'"/> </td>'
						+'</tr>'
		   	        }
		    	 }
			}
			$("#tbody").html(table_str)
		}
		
		
		//重新加载表格
		function loadTable(){
			var first_length=first.length;  	//一级属性长度
			var second_length=second.length;	//二级属性长度
			var table_str="";
			for(var i=0 ; i < first_length ; i++){
				for(var q=0;q<goodsSkuVos.length;q++){
		   	        var goodsSkuVosObj = goodsSkuVos[q];
		   	        if((goodsSkuVosObj.nameId+goodsSkuVosObj.valueId)==(firstValue[i]+secondValue[0])){
		   	        	table_str+='<tr id='+secondValue[0]+'>'
						 +'<td rowspan='+second_length+'>'+first[i]+'</td>' 
						+'<td class="firstValue" style="display:none">'+firstValue[i]+'</td>'
						+'<td class="secondValue" style="display:none">'+secondValue[0]+'</td>'
						+'<td class="firstName" style="display:none">'+first[i]+'</td>'
						+'<td class="secondName">'+second[0]+'</td>'
						+'<td><input type="text" class="price" value="'+goodsSkuVosObj.skuPrice+'"></td>'
						+'<td><input type="text" class="comisrate" value="'+goodsSkuVosObj.skuProfitPercent+'"></td>'
						+'<td><input type="text" class="brokage" value="'+goodsSkuVosObj.skuProfit+'"></td>'
						+'<td><input type="text" class="stock" value="'+goodsSkuVosObj.totalInventory+'"></td>'
						+'<td rowspan='+second_length+'><div id="'+firstValue[i]+'11" >'
						+'	<img src="'+goodsSkuVosObj.skuDetails+'" style="width:150px">'
						+'</div><input type="hidden" class="'+firstValue[i]+'" name="skuImagesPicker" value="'+goodsSkuVosObj.skuDetails+'"/> </td>'
						+'</tr>'
		   	        }
		    	 }
				for (var j=1 ; j < second_length ; j++) {
					
					for(var q=0;q<goodsSkuVos.length;q++){
			   	        var goodsSkuVosObj = goodsSkuVos[q];
			   	        if((goodsSkuVosObj.nameId+goodsSkuVosObj.valueId)==(firstValue[i]+secondValue[j])){
			   	        	table_str+='<tr id='+secondValue[j]+'>'
							+'<td class="firstValue" style="display:none">'+firstValue[i]+'</td>'
							+'<td class="secondValue" style="display:none">'+secondValue[j]+'</td>'
							+'<td class="firstName" style="display:none">'+first[i]+'</td>'
							+'<td class="secondName">'+second[j]+'</td>'
							+'<td><input type="text" class="price" value="'+goodsSkuVosObj.skuPrice+'"></td>'
							+'<td><input type="text" class="comisrate" value="'+goodsSkuVosObj.skuProfitPercent+'"></td>'
							+'<td><input type="text" class="brokage" value="'+goodsSkuVosObj.skuProfit+'"></td>'
							+'<td><input type="text" class="stock" value="'+goodsSkuVosObj.totalInventory+'"></td>'
							+'<td style="display:none"><input type="hidden" class="'+firstValue[i]+'" name="skuImagesPicker" value="'+goodsSkuVosObj.skuDetails+'" /> </td>'
							+'</tr>'
			   	        }
			    	 }
				}
			}
			$("#tbody").html(table_str)
		}
		
		function changeTableFrist(){
			var first_length=first.length;
			var table_str="";
			for(var i=0 ; i < first_length ; i++){
				table_str+='<tr>'
					 +'<td>'+first[i]+'</td>' 
					+'<td class="firstValue" style="display:none">'+firstValue[i]+'</td>'
					+'<td class="secondValue" style="display:none"></td>'
					+'<td class="firstName" style="display:none">'+first[i]+'</td>'
					+'<td><input type="text" class="price" value=""></td>'
					+'<td><input type="text" class="comisrate" value=""></td>'
					+'<td><input type="text" class="brokage" value=""></td>'
					+'<td><input type="text" class="stock" value=""></td>'
					+'<td><div id="'+firstValue[i]+'11"></div><input type="hidden" class="'+firstValue[i]+'" name="skuImagesPicker"/> </td>'
					+'</tr>'
			}
			$("#tbody").html(table_str)
		}
		
		
		//修改表格数据
		function changeTable(){
			var first_length=first.length;
			var second_length=second.length;
			
			var table_str="";
			
			for(var i=0 ; i < first_length ; i++){
				
				if(second_length==0){
					second[0]="未选择";
					return;
				}
				table_str+='<tr id='+secondValue[0]+'>'
					 +'<td rowspan='+second_length+'>'+first[i]+'</td>' 
					+'<td class="firstValue" style="display:none">'+firstValue[i]+'</td>'
					+'<td class="secondValue" style="display:none">'+secondValue[0]+'</td>'
					
					+'<td class="firstName" style="display:none">'+first[i]+'</td>'
					+'<td class="secondName">'+second[0]+'</td>'
					
					+'<td><input type="text" class="price" value=""></td>'
					+'<td><input type="text" class="comisrate" value=""></td>'
					+'<td><input type="text" class="brokage" value=""></td>'
					+'<td><input type="text" class="stock" value=""></td>'
					+'<td rowspan='+second_length+'><div id="'+firstValue[i]+'11"></div><input type="hidden" class="'+firstValue[i]+'" name="skuImagesPicker"/> </td>'
					+'</tr>'
							
				for (var j=1 ; j < second_length ; j++) {
					
					table_str+='<tr id='+secondValue[j]+'>'
					
					+'<td class="firstValue" style="display:none">'+firstValue[i]+'</td>'
					+'<td class="secondValue" style="display:none">'+secondValue[j]+'</td>'
					
					+'<td class="firstName" style="display:none">'+first[i]+'</td>'
					+'<td class="secondName">'+second[j]+'</td>'
					
					+'<td><input type="text" class="price" value=""></td>'
					+'<td><input type="text" class="comisrate" value=""></td>'
					+'<td><input type="text" class="brokage" value=""></td>'
					+'<td><input type="text" class="stock" value=""></td>'
					+'<td style="display:none"><input type="hidden" class="'+firstValue[i]+'" name="skuImagesPicker"/> </td>'
					+'</tr>'
				}
			}
			
			$("#tbody").html(table_str)
		}
		
		$("#detail").on("click","input",function(){
			checkbox();
			if (res.caption[0] != undefined && res.caption[1] != undefined){	
				changeTable();
			}else{
				changeTableFrist();
			}
		})
		
		function checkbox(){
			
			properNameAndVal=[];
			/* 父类点解复选框 */
			if($(".first").is(":visible")  ){
				first=[]
				firstValue = []
				
				var strImSele = "";
				for (var i=0;i<$(".first>input").length;i++) {
					if($(".first>input").eq(i).prop("checked")){
						first.push($(".first>input").eq(i).val())
						firstValue.push($(".first>input").eq(i).attr("id"))
						properNameAndVal.push(res.caption[0].id+","+res.caption[0].name+","+$(".first>input").eq(i).attr("id")+","+$(".first>input").eq(i).val())
						
						strImSele += "<option value=\""+$(".first>input").eq(i).attr("id")+"\">"+$(".first>input").eq(i).val()+"</option>";
					}
				}
			
				$('#goodsSkuimage').html(strImSele);
			}
			
			/* 子类点解复选框 */
			if($(".second").is(":visible")  ){
				second=[];
				secondValue=[];
				for (var i=0;i<$(".second>input").length;i++) {
					if($(".second>input").eq(i).prop("checked")){
						second.push($(".second>input").eq(i).val())
						secondValue.push($(".second>input").eq(i).attr("id"))
						properNameAndVal.push(res.caption[1].id+","+res.caption[1].name+","+$(".second>input").eq(i).attr("id")+","+$(".second>input").eq(i).val())
					}
				}
			}
			$("#properNameAndVal").val(properNameAndVal);
			
		}
 	}
	
	
 	 $(".batch-submit").on('click',function(){
 		var bacthprice = $(".bacthprice").val();
 		var bacthrate = $(".bacthrate").val();
 		var bacthbrokage = $(".bacthbrokage").val();
 		var bacthstock = $(".bacthstock").val();
 		
 		$("#tbody").find("tr").each(function(){
 			$(this).find(".price").val(bacthprice);
 			$(this).find(".comisrate").val(bacthrate);
 			$(this).find(".brokage").val(bacthbrokage);
 			$(this).find(".stock").val(bacthstock);
 		})
 	})
    
    //请求url
    var CONST_URL = {
        INIT_LIST: basePath + "${common_url}initGoodsSpu",
    	INIT_MAIN: basePath + "${common_url}init",
    	PRODUCT_PROPERTYS: basePath + "${common_url}getProductPropertys",
    	PRODUCT_PROPERTY_VALUES: basePath + "${common_url}getProductPropertyValues",
    	COMPANYS: basePath + "${common_url}companys",
    	EDIT: basePath + "${common_url}edit",
       	INIT_PROPERTY: basePath + "${common_url}initProperty",
       	GET_GOODS_BRAND: basePath + "${common_url}getGoodsBrand",
       	GET_GOODS_COMPANY: basePath + "${common_url}getGoodsCompany",
       	GET_CATEGORY: basePath + "${common_url}getGoodsCategorys",
    };
    
</script>
</body>
</html>